package com.lzy.cloud.order.utils;

import com.lzy.cloud.order.constants.BizRuleConstants;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class RuleUtil {

    /**
     * 房车租赁业务规则-退订
     *
     * @param workDate
     * @return
     */
    public static String CarRentRefundRule(Date workDate) {
        // 出行时间
        LocalDateTime startDateTime = LocalDateTime.ofInstant(workDate.toInstant(), ZoneId.of("Asia/Shanghai"));
        // 当前时间
        LocalDateTime now = LocalDateTime.now();
        if (startDateTime.toLocalDate().isEqual(now.toLocalDate())) {
            // 如果当天
            return BizRuleConstants.CarRentRule.CarRentStage.FIRST;
        } else {
            Duration duration = Duration.between(now, startDateTime);
            // 小时差，如果为负值则已经过期
            long hours = duration.toHours();
            if (hours >= BizRuleConstants.CarRentRule.CarRentCount.CARRENTCOUNT2.intValue()) {
                // 超过3天
                return BizRuleConstants.CarRentRule.CarRentStage.THIRD;
            } else if (hours >= BizRuleConstants.CarRentRule.CarRentCount.CARRENTCOUNT1.intValue()) {
                // 3天内,1天以上
                return BizRuleConstants.CarRentRule.CarRentStage.SENCOND;
            } else {
                // 当天或已过期
                return BizRuleConstants.CarRentRule.CarRentStage.FIRST;
            }
        }
    }

}
